<template>
  <div>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="500px" top="30vh" @close.native="cancel" :close-on-click-modal="false">
      <el-form ref="ruleForm" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="重命名：">
          <el-input v-model="form.name" />
        </el-form-item>
        <!-- <el-form-item label="重命名：" prop="newName">
          <el-input v-model="newName" placeholder="请输入新的流程图" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { update } from "@/api/file"
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        id: '',
        status: '',
        directoryId: '',
        name: ''
      },
      newName: '',
      rules: {
      },
      title: ''
    }
  },
  methods: {
    show(obj) {
      this.dialogVisible = true
      this.title = obj.title

      console.log('%c [  ]-43', 'font-size:13px; background:pink; color:#bf2c9f;', obj.data)
      if (obj.data) {
        this.form = Object.assign(this.form, obj.data)
      }
    },
    submitForm() {
      this.$refs['ruleForm'].validate(valid => {
        if (valid) {
          update({
            id: this.form.id,
            name: this.form.name,
            directoryId: this.form.directoryId,
            status: this.form.status
          }).then(() => {
            this.cancel()
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    cancel() {
      this.form = this.$options.data().form
      this.$refs.ruleForm.clearValidate()
      this.dialogVisible = false
      this.$emit('close')
    },

  }
}
</script>

<style lang="less" scoped>
</style>